using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Diagnostics;

namespace Watchdog2007.Dal {
    
    [DebuggerNonUserCode ()]
    public class DalSchedule : DalBase, ITimeStamp {

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        string tablename = "[dbo].[WdSchedule]";
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        string[] fields = { "Id", "Type", "Paused", "DateStart", "HourStart", "DateStop", "HourStop", "RepeatInterval", "RepeatType", "Days", "Weeks", "Months", "LastRun", "NextRun" };
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        string[] keyfields = { "Id" };

        #region Constructors, Destructors & Initialization
        internal DalSchedule()
            : base() {
            base.WhereItems.Add(new WhereItem("1", 2));
            Initialize();
        }
        internal DalSchedule(int id)
            : base() {
            base.WhereItems.Add(new WhereItem("Id", id));
            Initialize();
        }
        internal DalSchedule(DataRow drow)
            : base(ref drow) {
            Initialize();
        }
        internal DalSchedule(bool collection, string sql)
            : base(true) {
            base.CollectionSql = sql;
            Initialize();
        }
        private new void Initialize() {
            base.TableName = tablename;
            base.TableFields = fields;
            base.KeyFields = keyfields;
            base.Initialize();
        }
        #endregion

        #region Field's
        public int Id {
            get { return (int)GetValue("Id"); }
        }
        internal bool Paused {
            get { return (bool)GetValue ( "Paused" ); }
            set { SetValue ( "Paused", value ); }
        }
        internal DateTime DateStart {
            get { return (DateTime)GetValue("DateStart"); }
            set { SetValue("DateStart", value); }
        }
        internal string HourStart {
            get { return (string)GetValue("HourStart"); }
            set { SetValue("HourStart", value); }
        }
        internal DateTime DateStop {
            get { return (DateTime)GetValue("DateStop"); }
            set { SetValue("DateStop", value); }
        }
        internal string HourStop {
            get { return (string)GetValue("HourStop"); }
            set { SetValue("HourStop", value); }
        }
        internal int RepeatInterval {
            get { return (int)GetValue("RepeatInterval"); }
            set { SetValue("RepeatInterval", value); }
        }
        internal int RepeatType {
            get { return (int)GetValue("RepeatType"); }
            set { SetValue("RepeatType", value); }
        }
        internal DateTime NextRun {
            get { return (DateTime)GetValue ( "NextRun" ); }
            set { SetValue ( "NextRun", value ); }
        }
        internal DateTime LastRun {
            get { return (DateTime)GetValue ( "LastRunr" ); }
            set { SetValue ( "LastRun", value ); }
        }
        #region WeeklySchedule

        internal int Days {
            get { return (int)GetValue("Days"); }
            set { SetValue("Days", value); }
        }
        internal int Weeks {
            get { return (int)GetValue("Weeks"); }
            set { SetValue("Weeks", value); }
        }

        #endregion
        #region MonthlySchedule
        internal int Months {
            get { return (int)GetValue("Months"); }
            set { SetValue("Months", value); }
        }
        #endregion
        #endregion

        #region Statics
        internal static string GetFieldList() {
            DalSchedule obj = new DalSchedule();
            string list = "select ";
            string comma = "";
            foreach (string s in obj.fields) {
                list += comma + obj.tablename + ".[" + s + "]";
                comma = ", ";
            }
            if (obj.HasTimeStampFields)
                list += ", " + obj.tablename + ".[Created], " + obj.tablename + ".[Modified] ";
            list += "from ";
            obj.Dispose();
            return list;
        }
        #endregion

        #region ITimeStamp Members

        public DateTime Created {
            get {
                if (GetValue("Created") != null)
                    return (DateTime)GetValue("Created");
                return DateTime.MinValue;
            }
        }

        public DateTime Modified {
            get {
                if (GetValue("Modified") != null)
                    return (DateTime)GetValue("Modified");
                return DateTime.MinValue;
            }
        }

        #endregion

        #region Equality
        public override int GetHashCode() {
            return Id;
        }
        public static bool operator ==(DalSchedule lt1, DalSchedule lt2) {
            if (System.Object.ReferenceEquals(lt1, lt2))
                return true;

            if ((object)lt1 == null || (object)lt2 == null)
                return false;
            return lt1.Equals(lt2);
        }
        public static bool operator !=(DalSchedule lt1, DalSchedule lt2) {
            if (lt1 == null || lt2 == null)
                return false;
            return !(lt1 == lt2);
        }

        public override bool Equals(object obj) {
            if (!(obj is DalSchedule))
                return false;
            return (this.CompareTo(obj) == 0);
        }

        private int CompareTo(object obj) {
            if (!(obj is DalSchedule)) {
                throw new ArgumentException("A DalSchedule object is required for comparison.");
            }
            return this.Id.CompareTo(((DalSchedule)obj).Id);
        }
        #endregion
    }
}
